
const titles=document.querySelectorAll('.titles a')
const imgs=document.querySelectorAll('.imgs a')
let curIndex=0,timer=null

function removeActive(){
    titles.forEach(item=>{
        item.classList.remove('active')
    })
    imgs.forEach(item=>{
        item.classList.remove('active')
    })
}

function changeBanner(index){
    removeActive()
    titles[index].classList.add('active')
    imgs[index].classList.add('active')
}

function autoBanner(){
    timer=setInterval(function(){
        curIndex++
        if(curIndex>titles.length-1){
            curIndex=0
        }
        changeBanner(curIndex)
    },3000)
}
titles.forEach((item,index)=>{
    item.addEventListener('mouseenter',function(){
        curIndex=index
        changeBanner(index)
        clearInterval(timer)
    })
    item.addEventListener('mouseleave',function(){
        autoBanner()
    })
})

autoBanner()

let searchBar = document.querySelector(".searchBar")
let clear = document.querySelector(".clear")
let value = document.querySelector('[type=text]')   /*ѡ�п�Ϊtext������*/
let btn = document.querySelector('.goBtn')

searchBar.addEventListener('mouseenter', () => {
    searchBar.classList.toggle("changeWidth")
})

searchBar.addEventListener('mouseleave', () => {
    searchBar.classList.remove("changeWidth")
})

clear.addEventListener('click', function () {
    value.value = ''
})
//���ʵ�����ұ任�Ĺ���
const lunbo = document.getElementById('lunbo');
const leftBtn = document.getElementById('left');
const rightBtn = document.getElementById('right');

let currentIndex = 0;

rightBtn.addEventListener('click', () => {
    if (currentIndex < 4) {
        currentIndex++;
    } else {
        currentIndex = 0;
    }
    updateCarousel();
});

leftBtn.addEventListener('click', () => {
    if (currentIndex > 0) {
        currentIndex--;
    } else {
        currentIndex = 4;
    }
    updateCarousel();
});

function updateCarousel() {
    const translateValue = -currentIndex * 100 + '%';
    lunbo.style.transform = 'translateX(' + translateValue + ')';
}

